import { MockMethod } from 'vite-plugin-mock'

const random = (min, max) => Math.floor(Math.random() * (max - min + 1) + min)

const mockList: MockMethod[] = [
  {
    url: '/mock/login',
    method: 'post',
    statusCode: 200,
    response: ({ body }) => {
      const { username, password } = body
      let data: any = {}

      if (username === 'admin' && password === '123123') {
        data = {
          // 返回的结果集
          statusCode: 200,
          desc: '登录成功',
          data: {
            id: random(10000, 99999).toString(),
            token: `JWT${random(10000, 99999)}-JWT${random(10000, 99999)}-JWT${random(10000, 99999)}`
          }
        }
      } else {
        data = {
          // 返回的结果集
          statusCode: 0,
          desc: '账号或密码错误',
          data: null
        }
      }
      return data
    }
  },
  {
    url: '/mock/getUserInfo',
    method: 'get',
    statusCode: 200,
    response: () => {
      return {
        statusCode: 200,
        desc: '获取成功',
        data: {
          id: 0,
          name: 'admin',
          token: 'token.JWT.token',
          avatar: 'dfsdfsfdsvsfew'
        }
      }
    }
  },
  {
    url: '/mock/getUserList',
    method: 'get',
    // timeout: 3000,
    statusCode: 200,
    response: () => {
      return {
        statusCode: 200,
        desc: '获取成功',
        data: [
          {
            id: 1,
            name: '张三',
            createTime: '2022-05-05',
            updateTime: '2022-05-05'
          },
          {
            id: 2,
            name: '李四',
            createTime: '2022-05-05',
            updateTime: '2022-05-05'
          }
        ]
      }
    }
  }
]

export default mockList
